package sjjg.op;

import java.util.ArrayList;
import java.util.List;

public class FCFS {
    public static void main(String[] args) {
        List<Job> jobs = new ArrayList<>();
        Job a = new Job("a", 0,4);
        jobs.add(a);
        Job b = new Job("b", 2,7);
        jobs.add(b);
        Job c = new Job("c", 5,4);
        jobs.add(c);
        Job d = new Job("d", 8,3);
        jobs.add(d);
        Job e = new Job("e", 10,2);
        jobs.add(e);
        jobs.sort(( job1, job2)->{
             return (int) (job1.getToTime()-job2.getToTime());
        });
       double time=0;
       double totalR=0;
       double totalWRTime=0;
        for (Job job : jobs) {
            double t=Math.max(time,job.getToTime());
            job.setFinishTime(t+job.getServeTime());
            time=job.getFinishTime();

            job.setAvgRTime(job.getFinishTime()-job.getToTime());
            job.setWeightRTime(job.getAvgRTime()/job.getServeTime());
            job.setAvgWeightRTime(job.getWeightRTime()/jobs.size());
            totalR+=job.getAvgRTime();
            System.out.println("总的周转时间:"+totalR);
            totalWRTime+=job.getWeightRTime();
            System.out.println("总的带权周转时间:"+totalWRTime);
            System.out.println(job.getName()+"完成时间:"+job.getFinishTime());
            System.out.println(job.getName()+"周转时间:"+job.getAvgRTime());
            System.out.println(job.getName()+"平均带权周转时间:"+job.getAvgWeightRTime());
            System.out.println(job.getName()+"带权周转时间:"+job.getWeightRTime());
            System.out.println("-------------------------------------------------------");
        }
    }
}
